package com.traffic.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.traffic.annotation.ApiJsonObject;
import com.traffic.annotation.ApiJsonProperty;
import com.traffic.entity.Friend;
import com.traffic.service.FriendService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.traffic.constant.Status;
import com.traffic.model.ApiResponse;

import java.util.Map;

@Api(tags = "好友相关接口")
@RestController
@RequestMapping(value = "/friend")
@Slf4j
public class FriendController {

    @Autowired
    private FriendService friendService;

    @ApiOperation(value = "【添加好友】", notes = "添加")
    @GetMapping("/add/{uid}/{tid}")
    @ApiJsonObject(name = "Param",value = {
            @ApiJsonProperty(type =Integer.class,key = "user_id",example = "1" , description = "用户id"),
            @ApiJsonProperty(type =Integer.class,key = "target_id",example = "2" , description = "好友id"),
    })
    public ApiResponse addFriend(@PathVariable Long uid, @PathVariable Long tid) {


        Boolean result = friendService.apply(uid, tid);
        if (result) {
            return ApiResponse.ofStatus(Status.OK);
        }else {
            return ApiResponse.ofStatus(Status.COMMON_ERROR);
        }

    }

    @ApiOperation(value = "【接受好友请求】", notes = "接受好友请求，我应该是targetId一方 传入id为申请信息中的id")
    @GetMapping("/accept/{id}")
    public ApiResponse accept(@PathVariable Long id) {
        if (friendService.accept(id)){
            return ApiResponse.ofStatus(Status.OK);
        }
        return ApiResponse.ofStatus(Status.COMMON_ERROR);
    }

    @ApiOperation(value = "【拒绝好友请求】", notes = "拒绝好友请求，我应该是targetId一方 传入id为申请信息中的id")
    @GetMapping("/refuse/{id}")
    public ApiResponse refuse(@PathVariable Long id) {
        if (friendService.refuse(id)) {
            return ApiResponse.ofStatus(Status.OK);
        }
        return ApiResponse.ofStatus(Status.COMMON_ERROR);
    }

    @ApiOperation(value = "【获取好友列表】", notes = "传入用户id")
    @GetMapping("/f/list/{id}")
    public ApiResponse getFriendList(@PathVariable Long id) {
        return ApiResponse.ofStatus(Status.OK, friendService.getFriendList(id));
    }

    @ApiOperation(value = "【好友信息】", notes = "传入用户id status 0-发起申请 1-已接受 2-已拒绝")
    @GetMapping("/i/list/{id}")
    public ApiResponse getInfoList(@PathVariable Long id) {
        return ApiResponse.ofStatus(Status.OK, friendService.getInfoList(id));
    }

    @ApiOperation(value = "【删除好友】", notes = "传入用户id 好友id")
    @GetMapping("/delete/{userId}/{targetId}")
    public ApiResponse delete(@PathVariable Long userId, @PathVariable Long targetId) {
        if (friendService.delete(userId, targetId)) {
            return ApiResponse.ofStatus(Status.OK);
        }
        return ApiResponse.ofStatus(Status.COMMON_ERROR);
    }

}
